function secondsToTime(secs){
    var hours = Math.floor(secs / (60 * 60));
    var divisor_for_minutes = secs % (60 * 60);
    var minutes = Math.floor(divisor_for_minutes / 60);
    var divisor_for_seconds = divisor_for_minutes % 60;
    var seconds = Math.ceil(divisor_for_seconds);
    if(hours<10) hours='0'+hours;
    if(minutes<10) minutes='0'+minutes;
    if(seconds<10) seconds='0'+seconds;
    var time = hours+':'+minutes+':'+seconds;
    return time;
}
    
function buildTime(f_time, url){
    var text = document.getElementById('remaining');
    alert("text");
    if(text!=null){
        alert("asdasd");
        var d = new Date();
        var current_time = Math.floor(d.getTime()/1000);
        var diff = f_time-current_time;
        current_time = Math.floor(d.getTime()/1000);
        text.innerHTML = secondsToTime(diff);
    }
    setTimeout(function(){buildTime(f_time)}, 1000);
    if(diff<=0){
        var oRequest = new XMLHttpRequest();
        oRequest.open("GET",url,false);
        oRequest.setRequestHeader("User-Agent",navigator.userAgent);
        oRequest.send(null);
        window.location.reload();
    }
}